
function alignObjectKeys(obj, spaceLength = 4) {
  const keys = Object.keys(obj)
  const keyLengths = keys.map(key => key.length)
  
  const max = Math.max.apply( Math, keyLengths );
  const newObj = {}
  let keyName
  
  keys.forEach(key => {
    
    keyName = key
    
    if (keyName.length < max) {
      keyName += ' '.repeat(max - key.length)
    }
    
    keyName += ' '.repeat(spaceLength)
    
    newObj[keyName] = obj[key]
  })
  
  return newObj
}

function getObjectItemMaxLength(obj) {
  const arr = Object.keys(obj)
  const keyLengths = arr.map(key => key.length)
  const max = Math.max.apply( Math, keyLengths )
  
  return max
}

module.exports = {
  alignObjectKeys,
  getObjectItemMaxLength
}